package com.gxa.zhonglong.service.impl;

import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.mapper.StoneClarityMapper;
import com.gxa.zhonglong.pojo.StoneClarity;
import com.gxa.zhonglong.service.StoneClarityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author NITRO
 */

@Service("stoneClarityService")
@Transactional(rollbackFor = {Throwable.class})
public class StoneClarityServiceImpl implements StoneClarityService {

    @Autowired
    private StoneClarityMapper stoneClarityMapper;


    @Override
    public Boolean addStoneClarity(StoneClarity stoneClarity) throws BusinessException {
        StoneClarity stoneClarity1 = stoneClarityMapper.selectStoneClarityByCode(stoneClarity.getClarityCode());
        if (stoneClarity1 == null) {
            stoneClarityMapper.addStoneClarity(stoneClarity);
            return true;
        }
        throw  new BusinessException(ExceptionCode.ADD_DEFEATED);
    }

    @Override
    public void deleteStoneClarity(List<Long> ids) throws BusinessException {
       if(stoneClarityMapper.deleteStoneClarity(ids)<1){
           throw  new BusinessException(ExceptionCode.DELETE_FALSE);
       }
    }

    @Override
    public Boolean updateStoneClarity(StoneClarity stoneClarity) throws BusinessException {
        Boolean aBoolean = stoneClarityMapper.updateStoneClarity(stoneClarity);
        if (aBoolean) {
            return true;
        }
        throw  new BusinessException(ExceptionCode.UPDATE_FALSE);
    }

    @Override
    public List<StoneClarity> getStoneClarity() {
        List<StoneClarity> stoneClarities = stoneClarityMapper.selectStoneClarity();
        return stoneClarities;
    }
}
